//
//  SMForgetPasswordOneTableViewController.m
//  SaveMoney
//
//  Created by user on 2018/11/30.
//  Copyright © 2018年 Sunflower. All rights reserved.
//

#import "SMForgetPasswordOneTableViewController.h"

#import "SMForgetPasswordTwoTableViewController.h"

@interface SMForgetPasswordOneTableViewController ()
@property (weak, nonatomic) IBOutlet SBBaseTextField *accountTF;
@property (weak, nonatomic) IBOutlet SBBaseTextField *emailTF;

@end

@implementation SMForgetPasswordOneTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"确认用户";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1 || indexPath.row == 3) {
        return SBScaleNumber(50);
    } else if (indexPath.row == 0) {
        return SBScaleNumber(40);
    } else {
        return SBScaleNumber(20);
    }
    
}
- (IBAction)nextAction:(id)sender {
    
    if (![_accountTF.text isValidMobileNumberOrPhoneNumber]) {
        [SVProgressHUD showErrorWithStatus:@"账号输入错误"];
        return;
    } 
    if (![_emailTF.text isValidEmail]) {
        [SVProgressHUD showErrorWithStatus:@"邮箱错误"];
        return;
    }
    [SVProgressHUD show];
    [[NetworkAction sharedAction] isHaveUserWithPhone:_accountTF.text email:_emailTF.text success:^(id model, NSString *message) {
        [SVProgressHUD showSuccessWithStatus:@"用户已确认"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self performSegueWithIdentifier:@"changePassword" sender:(NSDictionary *)model[@"userid"]];
        });
    } failuer:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:[error localizedDescription]];
    }];
    
    
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"changePassword"]) {
        SMForgetPasswordTwoTableViewController *vc = segue.destinationViewController;
        vc.phone = _accountTF.text;
        vc.userId = sender;
    }
}


@end
